<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>openGauss Blog  | 新用户权限和permission denied for schema public</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    
    <link rel="shortcut icon" href="https://xzx666.gitee.io/lookeng/img/favicon.ico" type="image/x-icon" />
    <link rel="apple-touch-icon" href="https://xzx666.gitee.io/lookeng/img/apple-touch-icon.png" />

    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    
    <link rel="stylesheet" href="https://xzx666.gitee.io/lookeng/css/commen.css?t=1607593672000" />
    <link rel="stylesheet" href="https://xzx666.gitee.io/lookeng/css/blog.css?t=1607593672000" />
    <link rel="stylesheet" href="https://xzx666.gitee.io/lookeng/css/mobile.css?t=1607593672000" />
    <link rel="stylesheet" href="https://xzx666.gitee.io/lookeng/css/pagination.css?t=1607593672000">
    
    <script>
      var _hmt = _hmt || [];
      (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?34e9f585f29581007941aa1698181871";
        var s = document.getElementsByTagName("script")[0]; 
        s.parentNode.insertBefore(hm, s);
      })();
    </script>
</head>
<body>
  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src='//unpkg.com/valine/dist/Valine.min.js'></script>






<div class="container">
    <div class="columns blog-detail">
        <div class="post_detail">
            <div class="is-child box">
                <div class="breadCrumb"><a href="\zh\">博客/</a></div>
                <div class="blog-detail-header">
                    <h1>新用户权限和permission denied for schema public</h1>
                    <div class="blog-detail-prop">
                        <img src="https://xzx666.gitee.io/lookeng/img/icon-date.png">
                        <span class="article_right_date">2020-11-19</span>
                        <img src="https://xzx666.gitee.io/lookeng/img/icon-author.png">
                        <span class="article_right_author">盖国强</span>
                        <img src="https://xzx666.gitee.io/lookeng/img/icon-view.png">
                        <span id="/zh/post/gaiguoqiang/%E6%96%B0%E7%94%A8%E6%88%B7%E6%9D%83%E9%99%90%E5%92%8Cpermission-denied-for-schema-public/" class="leancloud_visitors" data-flag-title="新用户权限和permission denied for schema public">
                            <i class="leancloud-visitors-count"></i>                     
                        </span>
                    </div>
                    <div class="blog-detail-tags">
                        <img src="https://xzx666.gitee.io/lookeng/img/icon-tag.png">
                        
                        <a href="https://xzx666.gitee.io/lookeng/zh/tags/%E6%96%B0%E7%94%A8%E6%88%B7%E6%9D%83%E9%99%90%E5%92%8Cpermission-denied-for-schema-public">新用户权限和permission denied for schema public</a>
                        
                    </div>
                </div>
                <div class="content blog-content">
                    

<h1 id="新用户权限和permission-denied-for-schema-public-a-name-zh-cn-topic-0293240556-a">新用户权限和permission denied for schema public<a name="ZH-CN_TOPIC_0293240556"></a></h1>

<p>openGauss 安装完成后，会自动创建自定义的帐号，名称默认为omm。默认用户名omm和操作系统用户同名，我们可以通过<strong>REPLACE</strong>修改其密码。</p>

<pre><code>omm=# alter role omm identified by 'Open6au55' replace 'Gauss@123';
NOTICE:  The encrypted password contains MD5 ciphertext, which is not secure.
ALTER ROLE
omm=# alter role omm identified by 'Open6au55' replace 'Gauss@123';
ERROR:  The old password is invalid.
</code></pre>

<p>可以使用 omm 登录，创建一个新的用户，我们可以看到 openGauss 对于密码安全的要求：</p>

<pre><code>omm=# create user enmotech with password 'enmotech';
ERROR:  Password must contain at least three kinds of characters.
omm=# 
omm=# create user enmotech with password 'Enm0t3ch';    
NOTICE:  The encrypted password contains MD5 ciphertext, which is not secure.
CREATE ROLE
</code></pre>

<p>创建独立的数据库，给用户授权：</p>

<pre><code>omm=# create database enmotech owner enmotech;
CREATE DATABASE
omm=# GRANT ALL PRIVILEGES ON DATABASE enmotech to enmotech;
GRANT
omm=# ALTER ROLE enmotech CREATEDB;
ALTER ROLE

omm=# \q
</code></pre>

<p>在操作系统上，连接到容器数据库中：</p>

<pre><code>[root@ecs-514e-0004 ~]# gsql -d enmotech -U enmotech -W'Enm0t3ch' -h 192.168.1.94 -p 8888
gsql ((openGauss 1.0 build ec0e781b) compiled at 2020-04-27 17:25:57 commit 2144 last mr 131 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type &quot;help&quot; for help.

enmotech=&gt;
</code></pre>

<p>注意，此时创建数据表还是遇到错误，不允许在 public 上创建：</p>

<pre><code>enmotech=&gt; create table yunhe (id number);
ERROR:  permission denied for schema public
</code></pre>

<p>类似的建表失败报错可能还累死：</p>

<pre><code>[Err] ERROR: permission denied for schema public
LINE 1: create table xxxx
</code></pre>

<p>这是因为安全原因，不允许普通客户在public模式下操作。</p>

<p>在测试需要下，可以将 ALL PRIVILEGES 授予 enmotech 用户，需要使用超级用户授权，这里是 omm 用户：</p>

<pre><code>omm=# GRANT ALL PRIVILEGES TO enmotech;
ALTER ROLE
</code></pre>

<p>系统权限又称为用户属性，包括SYSADMIN、CREATEDB、CREATEROLE、AUDITADMIN和LOGIN。</p>

<pre><code>omm=# \du
                                         List of roles
 Role name |                               Attributes                               | Member of 
-----------+------------------------------------------------------------------------+-----------
 enmotech  | Sysadmin                                                               | {}
 gaussdb   |                                                                        | {}
 omm       | Sysadmin, Create role, Create DB, Replication, Administer audit, UseFT | {}
</code></pre>

<p>现在 enmotech 这个用户，可以继续测试了：</p>

<pre><code>eygle=&gt; create table eygle(id number);
CREATE TABLE
eygle=&gt; drop table eygle;
DROP TABLE
</code></pre>

<p>在 openGauss 中，通过 sql 文件，加载数据也非常简单：</p>

<pre><code>eygle=&gt; \i /tmp/dan.sql
INSERT 0 1
INSERT 0 1
...
</code></pre>

                </div>
            </div>
            <div class="box" style="margin-top:15px;">
                <div style="font-size:14px;color:gray"><strong>【免责声明】</strong>本文仅代表作者本人观点，与本网站无关。本网站对文中陈述、观点判断保持中立，不对所包含内容的准确性、可靠性或完整性提供任何明示或暗示的保证。本文仅供读者参考，由此产生的所有法律责任均由读者本人承担。</div>
            </div>
            <div class="post-comment">
                
                  
  <link rel="stylesheet" href="https://xzx666.gitee.io/lookeng/css/custom.css" />
  <div id="vcomments" lang="zh-cn" mess="说点什么吧..."></div>

  <script type="text/javascript">
    const placeholder = document.getElementById("vcomments").getAttribute("mess"),
          lang = document.getElementById("vcomments").getAttribute("lang");
    const  langs = lang == "zh-cn" ? "zh-cn" : "en";
    new Valine({
        el: '#vcomments' ,
        appId: '6wfgavgIRqmpC3hjHqQVtFWF-gzGzoHsz',
        appKey: 'QRqrBDBB0p0YhrGe9IJ169ip',
        avatar:'mm', 
        placeholder: placeholder,
        visitor: true,
		    meta: ['nick','mail','link'],
        lang: langs
    });
  </script>
            </div>
        </div>
    </div>
</div>
<script>
    $(function (){
        var query = new AV.Query('Counter');
        query.equalTo('url', decodeURIComponent('\/zh\/post\/gaiguoqiang\/%E6%96%B0%E7%94%A8%E6%88%B7%E6%9D%83%E9%99%90%E5%92%8Cpermission-denied-for-schema-public\/'));
        query.find().then(function (data) {
            if(data.length && (data[0].attributes.author === 'openGauss')){
                var counter = AV.Object.createWithoutData('Counter', data[0].id);
                counter.set('author', '盖国强');
                counter.save();
            }
        })
    })
</script>







<input id="iframeUrl" type="text" style="display: none;" value=https://xzx666.gitee.io/>




<script defer src="https://xzx666.gitee.io/lookengjs/all.js"></script>
<script src="https://xzx666.gitee.io/lookengjs/flexible.js"></script>
<script>
  const hash = window.location.search,
        pageurl = window.location.href;
  var langss = document.querySelector("html").lang === "zh-cn" ? "zh" : "en";
  console.log("hash:",hash,"pageurl:",pageurl,"ttr",pageurl.split(langss + "/")[1])

  if(!document.getElementById("vcomments")) {
    new Valine({
        appId: '6wfgavgIRqmpC3hjHqQVtFWF-gzGzoHsz',
        appKey: 'QRqrBDBB0p0YhrGe9IJ169ip',
        avatar:'mm',
        visitor: true,
		    meta: ['nick','mail','link']
    });
  }
 
  
    


    const url = document.getElementById("iframeUrl").value;

    function observe (el, options, callback) {
      var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver
      var observer = new MutationObserver(callback)
      observer.observe(el, options)
    }

    var options = {
        childList: true,
        subtree: true,
        characterData: true
      }
    observe(document.body, options, (records, instance) => {
    const height = document.body.scrollHeight;
    parent.postMessage(height,url);
    })
    if(pageurl.split(langss + "/")[1]) parent.postMessage(pageurl.split(langss + "/")[1],url);
    

    if(document.querySelector("#notFound")) parent.postMessage("我404了",url);

</script>
</body>
</html>
